package com.zhou.common.base.mq.mq;

import com.aliyun.openservices.ons.api.bean.OrderProducerBean;
import com.aliyun.openservices.ons.api.bean.ProducerBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author li.ke
 * @date 2021/2/20
 */
@Configuration
@ConditionalOnProperty(prefix = "rocketmq", name = "enable", havingValue = "false", matchIfMissing = true)
public class MqProducerClient {
    @Autowired
    private MqConfig mqConfig;

    @Bean(initMethod = "start", destroyMethod = "shutdown", name = "producer")
    public ProducerBean buildProducer() {
        ProducerBean producer = new ProducerBean();
        producer.setProperties(mqConfig.getMqProperties());
        return producer;
    }

    @Bean(initMethod = "start", destroyMethod = "shutdown", name = "orderProducer")
    public OrderProducerBean buildOrderProducer() {
        OrderProducerBean producer = new OrderProducerBean();
        producer.setProperties(mqConfig.getMqProperties());
        return producer;
    }
}
